package com.mars.dbhandler.service;

import com.alibaba.fastjson.JSON;
import com.mars.dbhandler.dao.OrderMapper;
import com.mars.dbhandler.entity.Order;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@RabbitListener(queues = "objectQueue")
public class OrderService {

    @Autowired
    private AmqpTemplate amqpTemplate;

    @Autowired
    OrderMapper orderMapper;

    @RabbitHandler
    public void OrderHandle(String orderString){
        Order order = JSON.parseObject(orderString,Order.class);
        orderMapper.addOrder(order);
    }

}
